package cn.yuanqiao.framework.security.handle;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert;

import java.util.Collection;

/**
 * @ClassName: TenantUsernamePasswordAuthenticationToken
 * @Description: 类的描述
 * @author: lihuahua
 * @date: 2024/3/9 15:47
 * @Blog: huahuacoco.top
 */

import java.util.Collection;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert;

public class TenantUsernamePasswordAuthenticationToken extends AbstractAuthenticationToken {
    private static final long serialVersionUID = 550L;
    private final Object principal;
    private Object credentials;
    private Object tenantCode;

    public TenantUsernamePasswordAuthenticationToken(Object principal, Object credentials) {
        super((Collection)null);
        this.principal = principal;
        this.credentials = credentials;
        this.setAuthenticated(false);
    }

    public TenantUsernamePasswordAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        super.setAuthenticated(true);
    }

    public TenantUsernamePasswordAuthenticationToken(Object principal, Object credentials,Object tenantCode) {
        super((Collection)null);
        this.principal = principal;
        this.credentials = credentials;
        this.tenantCode = tenantCode;
        this.setAuthenticated(false);
    }

    public TenantUsernamePasswordAuthenticationToken(Object principal, Object credentials, Object tenantCode, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        this.tenantCode = tenantCode;
        super.setAuthenticated(true);
    }
    

    @Override
    public Object getCredentials() {
        return this.credentials;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }

    public Object getTenantCode() {
        return this.tenantCode;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        Assert.isTrue(!isAuthenticated, "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
        super.setAuthenticated(false);
    }

    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
        this.credentials = null;
    }
}
